# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=minidlna
pkgver=1.3.3
pkgrel=0
pkgdesc="DLNA/UPnP-AV compliant media server"
url="https://sourceforge.net/projects/minidlna/"
arch="all"
license="GPL-2.0-or-later AND BSD-3-Clause"
makedepends="
	autoconf
	automake
	bsd-compat-headers
	ffmpeg-dev
	flac-dev
	gettext-dev
	libexif-dev
	libid3tag-dev
	libjpeg-turbo-dev
	libogg-dev
	libtool
	libvorbis-dev
	sqlite-dev
	zlib-dev
	"
install="minidlna.pre-install minidlna.post-upgrade"
subpackages="$pkgname-doc $pkgname-lang $pkgname-openrc"
pkgusers="$pkgname"
pkggroups="$pkgname"
source="https://downloads.sourceforge.net/project/minidlna/minidlna/$pkgver/minidlna-$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	libav-fix.patch
	"

# secfixes:
#   1.3.2-r0:
#     - CVE-2022-26505
#   1.2.1-r2:
#     - CVE-2020-28926
#     - CVE-2020-12695

prepare() {
	default_prepare
	sh autogen.sh
}

build() {
	CFLAGS="$CFLAGS -fcommon" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--with-os-name="Alpine Linux" \
		--with-os-version=3.13.0 \
		--with-os-url="https://www.alpinelinux.org" \
		--with-db-path=/var/lib/minidlna \
		--with-log-path=/var/log/minidlna
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	install -dm750 -o $pkgusers -g $pkggroups \
		"$pkgdir/var/lib/$pkgname" \
		"$pkgdir/var/log/$pkgname"
	install -m755 -D "$srcdir/$pkgname.initd" \
		"$pkgdir/etc/init.d/$pkgname"
	install -m644 -D "$srcdir/$pkgname.confd" \
		"$pkgdir/etc/conf.d/$pkgname"
	install -m644 -D "$pkgname.conf" \
		"$pkgdir"/etc/$pkgname.conf
	install -Dm644 "$srcdir"/$pkgname-$pkgver/minidlna.conf.5 \
		"$pkgdir"/usr/share/man/man5/minidlna.conf.5
	install -Dm644 "$srcdir"/$pkgname-$pkgver/minidlnad.8 \
		"$pkgdir"/usr/share/man/man8/minidlnad.8
}

sha512sums="
3571af71b49d46aacc273a9b35e2c78aeccb966c1d6122f8186074c34f9a177ac60622ccf29f307d8d73f502c7a99f023f96f0c43bbd398c7ef82bb57d77cc1d  minidlna-1.3.3.tar.gz
e16961bb68c004297f1e26422b1d15bd8583ba2e0e36c88902a45573b685993fff88d2d0dae8c624eaeddb0deca614dbc13b8345f34b4c348961c00b05c0df30  minidlna.initd
e209848af0d79069ac989ad61d3be610b4c0c2783a207a50463a25ec3811b04d1da3a2acde54749878bec44e1567874ede827b978d5472c00f6a855663e5cbf8  minidlna.confd
ead73ca2dd3222013018a10a8aeba588c20dd4b232d5cc39af2bf9ee600bf783106580a1bb38101a0654525b661236c1fe995ba1394dca3f2b2e10ca8132d87d  libav-fix.patch
"
